package com.duanruan.bmgl.controller;

import com.duanruan.bmgl.common.JsonData;
import com.duanruan.bmgl.entity.Employee;
import com.duanruan.bmgl.entity.EmployeeVo;
import com.duanruan.bmgl.service.EmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xiaolong
 * @create 2020-08-22 9:23
 * @description 员工controller
 */
@RestController
@RequestMapping("/employees")
public class EmployeeController {
    @Resource(name = "EmployeeServicebmgl")
    private EmployeeService employeeService;

    //根据部门id查找员工信息
    @GetMapping
    public JsonData findEmployeebyid(String departmentId,int page,int limit){
        PageHelper.startPage(page,limit);
        List<Employee> employees=employeeService.findEmployees(departmentId);
        PageInfo<Employee> pageInfo=new PageInfo<>(employees);
        int totalnums=(int)pageInfo.getTotal();
        int totalpages=pageInfo.getPages();
        EmployeeVo employeeVo=new EmployeeVo()
                .setEmployees(employees).setPage(page).setLimit(limit)
                .setTotalnums(totalnums).setTotalpages(totalpages);
        return JsonData.success("查询成功",employeeVo);
    }

}
